package cn.mooncode.basketballManage.service.impl;

import cn.mooncode.basketballManage.pojo.RespBean;
import cn.mooncode.basketballManage.pojo.RespPageBean;
import cn.mooncode.basketballManage.service.IMatchService;
import cn.mooncode.basketballManage.mapper.MatchMapper;
import cn.mooncode.basketballManage.pojo.Match;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jwz
 * @since 2021-03-28
 */
@Service
public class MatchServiceImpl extends ServiceImpl<MatchMapper, Match> implements IMatchService {

    @Autowired
    private MatchMapper matchMapper;

    /**
     * 获取所有比赛信息
     * @param currentPage
     * @param size
     * @param match
     * @return
     */
    @Override
    public RespPageBean getAllMatches(Integer currentPage, Integer size, Match match) {
        Page<Match> page = new Page<>(currentPage, size);
        IPage<Match> ipage = matchMapper.getAllMatches(page, currentPage, size);
        return new RespPageBean(ipage.getTotal(), ipage.getRecords());
    }

    /**
     * 获取当前比赛信息
     * @param currentPage
     * @param size
     * @param match
     * @param tid
     * @return
     */
    @Override
    public RespPageBean getCurrentMatches(Integer currentPage, Integer size, Match match, Integer tid) {
        Page<Match> page = new Page<>(currentPage, size);
        IPage<Match> iPage = matchMapper.getCurrentMatches(page, currentPage, size, tid);
        return new RespPageBean(iPage.getTotal(), iPage.getRecords());
    }

    @Override
    public RespBean addResult(Integer id, String result) {
        if (matchMapper.addResult(id, result)) {
            return RespBean.success("添加成功！");
        }
        return RespBean.error("添加失败！");
    }
}
